<?php /* SVN: $Id: admin_index.ctp 2857 2010-08-27 05:22:44Z sakthivel_135at10 $ */ ?>
<div class="userViews index js-response">
<?php if(empty($this->request->params['named']['view_type'])) : ?>
<div class="page-count-block clearfix">
	    <div class="grid_left">
	      <?php echo $this->element('paging_counter'); ?>
		</div>
		<div class="grid_left">
            <?php echo $this->Form->create('ProjectView' , array('type' => 'get', 'class' => 'normal search-form clearfix','action' => 'index')); 
				$value = !empty($this->request->params['named']['q']) ? $this->request->params['named']['q'] : '';
			?>            
        			<?php echo $this->Form->input('q', array('label' => __l('Keyword'),'value'=>$value)); ?>
        	    	<?php echo $this->Form->submit(__l('Search'));?>
        	<?php echo $this->Form->end(); ?>
		</div>
  </div>
<?php endif; ?>
    <?php echo $this->Form->create('ProjectView' , array('class' => 'normal clearfix','action' => 'update')); ?>
    <?php echo $this->Form->input('r', array('type' => 'hidden', 'value' => $this->request->url)); ?>

    <table class="list">
        <tr>
            <?php if(empty($this->request->params['named']['view_type'])) : ?>
            <th class="select"><?php echo __l('Select'); ?></th>
            <?php endif; ?>
            <th class="actions"><?php echo __l('Actions');?></th>
			<?php if(empty($this->request->params['named']['view_type'])) : ?>
            <th class="dl"><div class="js-pagination"><?php echo $this->Paginator->sort(__l('Project'), 'Project.name');?></div></th>
			<?php endif; ?>
            <th><div class="js-pagination"><?php echo $this->Paginator->sort(__l('Viewed By'), 'User.username');?></div></th>            
            <th><?php echo __l('View Type'); ?></th>     
            <th><div class="js-pagination"><?php echo $this->Paginator->sort(__l('IP'), 'Ip.ip');?></div></th>
           	<th><div class="js-pagination"><?php echo $this->Paginator->sort(__l('Viewed On'),'created');?></div></th>
        </tr>
        <?php
               if (!empty($projectViews)):
            $i = 0;
            foreach ($projectViews as $projectView):
                $class = null;
                if ($i++ % 2 == 0) :
                    $class = ' class="altrow"';
                endif;
                ?>
                <tr<?php echo $class;?>>
                    <?php if(empty($this->request->params['named']['view_type'])) : ?>
                    <td class="select"><?php echo $this->Form->input('ProjectView.'.$projectView['ProjectView']['id'].'.id', array('type' => 'checkbox', 'id' => "admin_checkbox_".$projectView['ProjectView']['id'], 'label' => false, 'class' => 'js-checkbox-list')); ?></td>
                    <?php endif; ?>
                  		<td class="actions dl">
            <div class="action-block">
                <span class="action-information-block">
                    <span class="action-left-block">&nbsp;&nbsp;</span>
                        <span class="action-center-block">
                            <span class="action-info">
                                <?php echo __l('Action');?>
                             </span>
                        </span>
                    </span>
                    <div class="action-inner-block">
                    <div class="action-inner-left-block">
                        <ul class="action-link clearfix">
                    <li><?php echo $this->Html->link(__l('Delete'), array('action' => 'delete', $projectView['ProjectView']['id']), array('class' => 'delete js-delete', 'title' => __l('Delete')));?></li>
                               		 </ul>
    					</div>
    					<div class="action-bottom-block"></div>
    				  </div>
              </div>
        </td>
					<?php if(empty($this->request->params['named']['view_type'])) : ?>
	                    <td class="dl">
              <div class="clearfix">
              <?PHP
                         if($is_wallet_enabled)
                         {
                            $project_status = $projectView['Project']['ProjectStatus']['name'];
                         }
                           else
                           {
                             $project_status = str_replace("Refunded","Voided",$projectView['Project']['ProjectStatus']['name']);
                           }
                        ?>
                 <span title="<?php echo $this->Html->cText($project_status,false); ?>" class="project-atatus-info project-status-<?php echo $projectView['Project']['project_status_id'];?>">
                 <?php echo $this->Html->cText($project_status); ?>
                 </span>
						<?php echo $this->Html->link($this->Html->cText($this->Html->truncate($projectView['Project']['name'],90, array('ending' => '...'))), array('controller'=> 'projects', 'action'=>'view', $projectView['Project']['slug'], 'admin' => false), array('escape' => false,'title' => $this->Html->cText($projectView['Project']['name'],false)));?>
                </div>
                        </td>
					<?php endif; ?>
                    <td><?php echo !empty($projectView['User']['username']) ? $this->Html->link($this->Html->cText($projectView['User']['username']), array('controller'=> 'users', 'action'=>'view', $projectView['User']['username'], 'admin' => false), array('escape' => false,'title' => $this->Html->cText($projectView['User']['username'],false))) : __l('Guest');?></td>
					<td>
					
						<?php echo ($projectView['ProjectView']['project_view_type_id'] == ConstViewType::EmbedView)?__l('Embed'):__l('Normal');?>
					
					</td>
					<td class="dl">
                        <?php if(!empty($projectView['Ip']['ip'])): ?>							  
                            <?php echo  $this->Html->link($projectView['Ip']['ip'], array('controller' => 'users', 'action' => 'whois', $projectView['Ip']['ip'], 'admin' => false), array('target' => '_blank', 'title' => 'whois '.$projectView['Ip']['ip'], 'escape' => false)); ?> 
							<p>
							<?php 					
                            if(!empty($projectView['Ip']['Country'])):
                                ?>
                                <span class="flags flag-<?php echo strtolower($projectView['Ip']['Country']['iso2']); ?>" title ="<?php echo $projectView['Ip']['Country']['name']; ?>">
									<?php echo $projectView['Ip']['Country']['name']; ?>
								</span>
                                <?php
                            endif; 
							 if(!empty($projectView['Ip']['City'])):
                            ?>             
                            <span> 	<?php echo $projectView['Ip']['City']['name']; ?>    </span>
                            <?php endif; ?>
                            </p>
                        <?php else: ?>
							<?php echo __l('N/A'); ?>
						<?php endif; ?>    
					</td>
					<td><?php echo $this->Html->cDateTimeHighlight($projectView['ProjectView']['created']);?></td>
                </tr>
                <?php
            endforeach;
        else:
            ?>
            <tr>
                <td colspan="7" class="notice"><?php echo __l('No Project Views available');?></td>
            </tr>
            <?php
        endif;
        ?>
    </table>

    <?php
    if (!empty($projectViews)) :
        ?>
        <?php if(empty($this->request->params['named']['view_type'])) : ?>
        <div class="clearfix">
		<div class="admin-select-block grid_left">
            <?php echo __l('Select:'); ?>
            <?php echo $this->Html->link(__l('All'), '#', array('class' => 'js-admin-select-all','title' => __l('All'))); ?>
            <?php echo $this->Html->link(__l('None'), '#', array('class' => 'js-admin-select-none','title' => __l('None'))); ?>
        </div>
        <?php endif; ?>        
        <?php if(empty($this->request->params['named']['view_type'])) : ?>
    <div class="admin-checkbox-button grid_4 grid_left">
            <?php echo $this->Form->input('more_action_id', array('class' => 'js-admin-index-autosubmit', 'label' => false, 'empty' => __l('-- More actions --'))); ?>
        </div>
        <?php endif; ?>
		<div class="js-pagination grid_right">
            <?php echo $this->element('paging_links'); ?>
        </div>
		</div>
        <div class="hide">
            <?php echo $this->Form->submit('Submit');  ?>
        </div>
        <?php
    endif;
    echo $this->Form->end();
    ?>
</div>